import re

str1 = '/api/abc/def/ghi'
pattern = r'^/api'
replaceResult = re.sub(pattern, '', str1)
splitArr = replaceResult.split('/')

i = 0
for item in splitArr:
  if item == '':
    splitArr.pop(i)
  i = i + 1
print('_'.join(splitArr))
